pkgname=netperf
pkgver=2.7
pkgrel=0
arch=('i386' 'x86_64' 'riscv64' 'aarch64')
url="https://github.com/HewlettPackard/netperf"
license=('GPL')
source=("https://github.com/HewlettPackard/netperf/archive/netperf-$pkgver.$pkgrel.tar.gz" "http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess" "http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub")
md5sums=('e0d45b5bca1eee2aef0155de82366202' 'SKIP' 'SKIP')

build()
{
	cd "$srcdir/$pkgname-$pkgname-$pkgver.$pkgrel"
	if [[ $CARCH == 'riscv64' ]]; then
	    cp ../config.guess ../config.sub .
	fi

	# sendfile_tcp_stream() misses assignment of len and it is possible
	# for random len to trigger the following issue, so fix it.
	# stderr: netperf: data send error: sendfile: No space left on device
	# stderr: len was -1847701200 send_size was 5120
	sed -i 's/(netperf_sendfile/(len = netperf_sendfile/g' src/nettest_bsd.c

	local configure_flags=(
				--prefix="$pkgdir/lkp/benchmarks/$pkgname"
				--enable-demo
				--enable-unixdomain
				--enable-sctp
				--enable-dccp
				--enable-burst
	)

	CFLAGS="-std=gnu89 -fcommon" ./configure "${configure_flags[@]}"
	make
}

package() {
	cd "$srcdir/$pkgname-$pkgname-$pkgver.$pkgrel"
	make install
}
